if (window.console && console.firebug) {
	window.konsole = window.console;
	//konsole.info("konsole detected Firebug.");
} else {
	window.konsole = function() {
		//private members
		var messages = [];
		if (window.console) {
			messages.push("<i>Check the built-in console for other messages.</i>")
		}
		var alertTimeout = null;
		
		function doIntrusiveDebugging(){
			return (location.href.indexOf(konsole.debugEnabler) > -1);
		}
		function pushMsg(theMsg){
			messages.push(theMsg);
			clearTimeout(alertTimeout);
			alertTimeout = setTimeout('konsole.doAlert()', 800);
		}
		
		//public members
		return {
			//settings
			debugEnabler: "annoyMe", //if this is present anywhere in the URL, the message box will show in non-Firebug browsers
			
			//method that shows the goodies
			doAlert: function() {
				alertTimeout = null;
				if ( doIntrusiveDebugging() ) {
					//compose a message
					var comboMsg = "";
					try {
						//write a DIV with the cached log content
						var logDiv = document.createElement("div");
						logDiv.style.border = "2px dotted red";
						logDiv.style.padding = "4px";
						logDiv.style.backgroundColor = "#e0e0e0";
						logDiv.innerHTML = "<tt>" + messages.join("<br /><br />") + "</tt>";
						document.body.appendChild(logDiv);
					} catch (e) {
						//if all else fails, just alert it
						alert( messages.join("\n") );
					}
					window.status += messages.length + " messages written ";
					messages = [];
				}
			}
			,
			//Firebug replacements start here
			log: function(msg){
				if (window.console && window.console.log) {
					window.console.log(msg);
				} else {
					pushMsg("(log)... " + msg);
				}
			},
			debug: function(msg){
				if (window.console && window.console.debug) {
					window.console.log(msg);
				} else {
					pushMsg("(dbg)... " + msg);
				}
			}, 
			info: function(msg){
				if (window.console && window.console.info) {
					window.console.info(msg);
				} else {
					pushMsg("(info).. " + msg);
				}
			},
			warn: function(msg){
				if (window.console && window.console.warn) {
					window.console.warn(msg);
				} else {
					pushMsg("<b>[warn! ] </b>" + msg);
				}
			},
			error: function(msg){
				if (window.console && window.console.error) {
					window.console.error(msg);
				} else {
					pushMsg("<b style='color:red'>ERROR: " + msg + "</b>");
				}
			},
			group: function(msg){
				msg = msg || "";
				if (window.console && window.console.group) {
					window.console.group(msg);
				} else {
					pushMsg("<p style='border-left:1px solid black'>" + msg);
				}
			},
			groupEnd: function(){
				if (window.console && window.console.groupEnd) {
					window.console.groupEnd();
				} else {
					pushMsg("</p>");
				}
			},
			dir: function(obj){
				if (window.console && window.console.dir) {
					window.console.dir(obj);
				} else {
					try {
						pushMsg( YAHOO.lang.JSON.stringify(obj, null, 20) );
					} catch(yahooErr) {
						try {
							pushMsg( JSON.stringify(obj) );
						} catch(jsonErr) {
							pushMsg("<i>JSON stringify failed or is disabled.</i><br />--" + yahooErr.message + "<br />--" + jsonErr.message);
						}
					}
				}
			},
			time: function(name){
				name = name || "anonymous";
				if (window.console && window.console.time) {
					window.console.time();
				} else {
					pushMsg(name + " timer started @ " + new Date().getTime());
				}
			},
			timeEnd: function(name){
				name = name || "anonymous";
				if (window.console && window.console.timeEnd) {
					window.console.timeEnd();
				} else {
					pushMsg(name + " timer stopped @ " + new Date().getTime());
				}
			}
		}
	}();
	
	konsole.info("Created konsole");
}

/* tests */
//konsole.time();
//konsole.log("Hello world!");
//konsole.info("I like the world!");
//konsole.warn("But it can be a cruel place...");
//konsole.error("Just beware of errors.");
//konsole.group("I'm going to dump something now.");
//konsole.dir( {iAmA:"testObject",index:1,nuthin:null} );
//konsole.groupEnd();
//konsole.timeEnd();
